<?php include("src/addPayment_cs.php"); ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link rel="shortcut icon" href="favicon.ico">
<link href="css/style.css" rel="stylesheet" type="text/css" />
<link href='css/coolMessage.css' type='text/css' rel='stylesheet' media='screen' />
<title>Add Payment :: First United Services LLC</title>
<script language="javaScript" type="text/javascript" src="js/jquery.js"></script>
<script language="javaScript" type="text/javascript" src="js/jquery.simplemodal.js"></script>
<script language="javaScript" type="text/javascript" src="js/coolMessage.js"></script>

<script language="javascript" type="text/javascript">
	
	function showMessage(show_msg){
		switch(show_msg){
			case 1://error
				coolMessage('error',"<?php echo $_SESSION["msg_cool"];?>");
			break;
			
			case 2://alert
				coolMessage('alert',"<?php echo $_SESSION["msg_cool"];?>");
			break;
			
			case 3://information
				coolMessage('information',"<?php echo $_SESSION["msg_cool"];?>", function (){ window.location.href = '/listClient.php'		});
			break;
			
			default:
				
			break;
		}
		return false;
	}	

	function validatePayment()
	{ 
		var msg    = '';
		
		var pay_value   	= document.getElementById("pay_value").value;
		var pay_comment		= document.getElementById("pay_comment").value;     

 		if(pay_value == '') 
			msg='- Please enter a Payment. \n';
		
		if(pay_comment == '') 
			msg= msg+'- Please write a comment about payment. \n';
		
	
		if(msg=='')
		{
			document.getElementById('form').submit();
			return true;
		}
		else
		{
			coolMessage("alert", msg);
			return false;
		}		
	}	
	
	function onlyNumbers(e){
		var key;
		if(window.event)
			key = window.event.keyCode;   //IE
		else
			key = e.which;                //firefox
		if (!( (key >= 48 && key <= 57) || key ==8 || key ==9 || key ==0 || key ==46 ))
			return false;
		else
			return true;
	}
	
	function validatePaymentValue(pay_value){
		pay_value = parseFloat(pay_value);
		var pay_balance = parseFloat(document.getElementById("pay_balance").value);
		if ( pay_value > pay_balance ){
			document.getElementById("pay_value").value = pay_balance;
			pay_value = pay_balance;
		}
		var new_balance_due = ( pay_balance - pay_value );
		
		document.getElementById("content_balance_due").innerHTML = new_balance_due;
	}
	
	function showCoolMessage(msg, type){		
		if ( type == 1 ){
			$.fn.fancybox.close();
			coolMessage("error", msg);
		}
		return false;
	}		
	
</script>
</head>
<body>
<?php $item_select = 5; include("menu.php");?><br />
 <form name="form" id="form" method="post" action="" enctype="multipart/form-data">
 <input type="hidden" name="add" id="add" value="1"/>		

    <div class="content_grv">
        <table width="90%" align="center" class="shadow">
            <tr>
                <td class="title">Payments</td>
            </tr>
            <tr>
                <td>
                    <table class="tbl_form" align="center">
                        
                        <tr>
                            <td align="right" width="35%"><span class="lbl_gray">Client Name:</span></td>
                            <td width="1%">&nbsp;</td>
                            <td>
                            <span class="lbl_black"><?php echo $my_case->cli_name." ".$my_case->cli_lastname; ?></span>
                            </td>
                        </tr>
                        <tr>
                            <td align="right"><span class="lbl_gray">Adviser:</span></td>
                            <td>&nbsp;</td>
                            <td><span class="lbl_black"><?php echo $my_case->use_name." ".$my_case->use_lastname; ?></span></td>
                        </tr>
                        <tr>
                            <td align="right"><span class="lbl_gray">Case Number:</span></td>
                            <td>&nbsp;</td>
                            <td>
                            	<input type="hidden" name="case_code" id="case_code" value="<?php echo $case_code;?>" />
	                            <span class="lbl_black"><?php echo $my_case->case_number; ?></span>
                            </td>
                        </tr>
                        <tr>
                            <td align="right"><span class="lbl_gray">Total Balance:</span></td>
                            <td width="1%">$</td>
                            <td>
                            	<span class="lbl_black"><?php echo $my_case->case_balance;?></span>
                            	<input type="hidden" name="case_balance" id="case_balance" value="<?php echo $my_case->case_balance;?>"/>
							</td>
                        </tr>
                        <tr>
                            <td align="right"><span class="lbl_gray">Payment:</span></td>
                            <td width="1%">$</td>
                            <td><input type="text" autocomplete="off" name="pay_value" id="pay_value" class="text_grv" size="21" maxlength="20" onKeyPress="return onlyNumbers(event)" onkeyup="javascript: validatePaymentValue(this.value)"/></td>
                        </tr>                        
                        <tr>
                            <td align="right"><span class="lbl_gray">Balance Due:</span></td>
                            <td width="1%">$</td>
                            <td>
	                            <span class="lbl_black" id="content_balance_due"><?php echo $pay_balance;?></span>
                                <input type="hidden" name="pay_balance" id="pay_balance" value="<?php echo $pay_balance;?>"/>
							</td>
                        </tr>
                        <tr>
                            <td align="right" valign="top"><span class="lbl_gray">Comment:</span></td>
                            <td>&nbsp;</td>
                            <td><textarea name="pay_comment" id="pay_comment" class="text_grv" cols="40" rows="7"></textarea></td>
                        </tr>
                        <tr>
                            <td colspan="3" align="center">
                             <input type="button" class="button_grv" value="Save" onclick="javascript: return validatePayment();" />
                             <input type="reset" value="Reset" class="button_grv"/>
                            <input type="button" class="button_grv" value="Cancel" onClick="javascript:window.history.back(-1);" />
                            </td>
                        </tr>
                    </table>
                </td>
            </tr>
        </table>
    </div>
</form>    
</body>
</html>
<?php include('divscoolmessage.php');?>